<?php
session_start();
require_once("settings.php");
require_once("functions.php");
loadLanguage();

$page_title = getLocalText("ui_authentication");

if(isset($_POST["userEmail"]) && isset($_POST["userPassword"])){
	$userEmail = filter_input(INPUT_POST , 'userEmail', FILTER_SANITIZE_EMAIL);
	$userPassword=encrypt($_POST["userPassword"]);
	$rs=executeQuery("SELECT * FROM user WHERE email='$userEmail' AND password='$userPassword'");
	if(mysqli_num_rows($rs) <= 0){
		$error_message = getLocalText("error_invalid_credentials");
	}else{
		$row = mysqli_fetch_assoc($rs);
		$_SESSION["email"] = $row["email"];
		$_SESSION["role"] = $row["role_id"];
		$_SESSION["id"] = $row["id"];
		header("Location: index.php");
	}
}
?>
<!DOCTYPE html>
<html lang="en">
	<?php include("./elements/header.php"); ?>
	<body>
		<div class="topcorner">
			<?php include("./elements/languageform.php")?>
		</div>
		<div class="container">
		  <?php include("./elements/loginform.php"); ?>
		</div>
		<?php include("./elements/footer.php"); ?>
	</body>
</html>